var utils = (function () {
    return {
        word_count: function (max_len, count_service) {// 真正计算字数是按三个字符，一个字数
            var val = 0, str = count_service.cal_key()
                + count_service.cal_val() + count_service.content;
            for (var i = 0, len = str.length; (i < len) && (val <= max_len * 3); i++) {
                var char = str.charCodeAt(i);
                if (char > 0 && char < 128)
                    val += 0.33334;
                else
                    val += 1;
            }
            var count = max_len - Math.floor(val);
            angular.element('.content_input').scope().count = count;
            var color = (count <= 16 && count > 2) ? '#f99'
                : (count <= 2) ? '#f00' : '#323748';
            $('.remain-count span').html(count).css('color', color);
            return Math.floor(val);
        },
        word_count_in2: function (max_len, count_service) {// 两个字符算一个字数
            var val = 0, kv_str = count_service.cal_key()
                + count_service.cal_val(), kv_len = kv_str.length, str = kv_str
                + count_service.content, truncate = '';
            for (var i = 0, len = str.length; (i < len) && (val <= max_len * 2); i++) {
                var char = str.charCodeAt(i);
                if (char > 0 && char < 128) {
                    val += 0.5;
                } else {
                    val += 1;
                }

                if (Math.floor(val) < max_len && i + kv_len < str.length) {
                    truncate += str[i + kv_len];
                }
            }
            // 返回字数，和不超过最大字数的字符串
            return {
                count: Math.floor(val),
                truncate: truncate
            };
        },
        // 转发的字段和页面angular字段不一致，需要转换
        insert_val: function (push) {// 将转发过来的数据插到页面
            var root_scope = angular.element(
                document.querySelectorAll('.content-inner')[0]).scope();
            for (var key in push) {
                for (var scope = root_scope.$$childHead; scope; scope = scope.$$nextSibling) {// 遍历4个controller
                    if (key != 'platform' && key in scope) {
                        switch (key) {
                            case 'timeToLive':
                                var push_time_content = ['默认(1天)', '0 - 不保留',
                                    '1分钟', '10分钟', '1小时', '3小时', '12小时', '3天',
                                    '10天', '自定义'], push_time_value = [86400,
                                    0, 60, 3600, 10800, 43200, 259200, 864000,
                                    -1];
                                if (push_time_value.indexOf(push.timeToLive) < 0) {
                                    scope.timeToLive = {
                                        value: -1,
                                        content: '自定义'
                                    };
                                    scope.custom_ttl = push.timeToLive;
                                } else {
                                    scope.timeToLive = {
                                        value: push['timeToLive'],
                                        content: push_time_content[push_time_value
                                            .indexOf(push['timeToLive'])]
                                    };
                                }
                                break;
                            case 'deliveryType':
                                scope.cur = push['deliveryType'] == 'now' ? 1 : 2;
                                break;
                            case 'receiverType':
                                scope.cur = push['receiverType'];
                                var arr = push['receiverValue'].split(',');
                                switch (scope.cur) {
                                    case 2:
                                        scope.tag_list = arr;
                                        break;
                                    case 3:
                                        scope.alias = arr;
                                        break;
                                    case 5:
                                        scope.regis_id = arr;
                                        break;
                                }
                                break;
                            case 'deliveryValue':
                                var v = push['deliveryValue'];
                                if (v != "null" && v != "0") {
                                    scope.durationTime = v;
                                    scope.solid_push = true;
                                }
                                break;
                            default:
                                scope[key] = push[key];
                        }
                        break;
                    }
                }
            }
        }
    }
})();

var app = angular.module("push_form", ['ui.bootstrap', 'ngSanitize']);
var authorization = BASE64
    .encoder("db1f3037515df21a53a976a4:36c507742ca440793ca43536");

app.directive("clickAnywhereButHere", clickAnywhereButHere);

function clickAnywhereButHere($document) {
    return {
        restrict: 'A',
        link: function (scope, elem, attr, ctrl) {
            elem.bind('click', function (e) {
                e.stopPropagation();
            });
            $document.bind('click', function () {
                scope.$apply(attr.clickAnywhereButHere);
            })
        }
    }
}

var platform_arr = [],
// max_words=[58,58,72,68],//不同平台的最大限制字数不同
// max_word=72;
    max_words = [666, 666, 1333, 1333], // 不同平台的最大限制字数不同
    max_word = 1333;
if (typeof app_data != 'undefined')
    platform_arr = app_data.platform.split(',');

app.factory('count_service', function () {
    return {
        key_list: [],// 附加字段的key数组
        val_list: [],
        content: '',
        cal_key: function () {
            return this.key_list.join('');
        },
        cal_val: function () {
            return this.val_list.join('');
        }
    };
});
app.controller('push_content', function ($scope) {
    $scope.line1 = '';// 预览图标题
    if (typeof app_data != 'undefined')
        $scope.line1 = app_data.appName ? app_data.appName : '';
    $scope.line2 = '';// 预览图内容
    $scope.content = '';

});
app
    .controller(
        'preview_content',
        function ($scope) {
            var platform = app_data.platform, is_android = platform
                .indexOf('a') > -1, is_ios = platform.indexOf('i') > -1, is_wp = platform
                .indexOf('w') > -1;
            // 预览图片和平台对应，如只有android,则预览图片组图只有android的预览
            $scope.start = is_android ? 0 : is_ios ? 1 : -1;
            $scope.end = is_ios ? 3 : is_android ? 0 : -1;
            $scope.num = [];// 预览图组数目
            if ($scope.start != -1 && $scope.end != -1)
                $scope.num.length = $scope.end - $scope.start + 1;

            $scope.cur = $scope.start;
            $scope.prev = function (i) {
                $scope.cur = i == $scope.start ? $scope.end : i - 1;
            };
            $scope.next = function (i) {
                $scope.cur = i == $scope.end ? $scope.start : i + 1;
            };
        });
app
    .controller(
        "content_input",
        function ($scope, count_service) {
            $scope.count = 0;
            $scope
                .$watch(
                    'content',
                    function (content) {
                        count_service.content = content;
                        var word_count = utils.word_count_in2(
                            35, count_service), count = word_count.count, truncate = word_count.truncate;
                        if (count <= 32)
                            $scope.$parent.line2 = content;
                        else
                        // 超过，后面加...
                            $scope.$parent.line2 = truncate
                                + '...';// 输入内容不全部显示

                        $scope.$on('gather_params', function () {
                            $scope.$emit('update_form', {
                                alert: content
                            });
                        });
                    });
        });

function tab($scope) {
    $scope.cur = 1;
    $scope.tab = function (i, event) {
        if (i != 6 && $scope.isOpen) {
            $("#segmentValue").select2("close")
        }
        $scope.cur = i;
        event.stopPropagation();
    };
}

app
    .config([
        '$httpProvider',
        function ($httpProvider) {
            // initialize get if not there
            if (!$httpProvider.defaults.headers.get) {
                $httpProvider.defaults.headers.get = {};
            }
            // disable IE ajax request caching
            $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
            // extra
            $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
            $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
        }]); // ng在ie下有缓存bug，导致新添加的seg之类的分类，不能及时显示，这里强制禁用缓存。

app
    .controller(
        'push_object',
        function ($scope, $rootScope, count_service, $http, $timeout) {
            tab($scope);
            $scope.cur = 4;// 广播
            $scope.input = '';
            $scope.alias = [];
            $scope.regis_id = [];
            $scope.distribute_push = [];
            $scope.receiverType = $scope.cur;
            $scope.platform = typeof app_data != 'undefined' ? app_data.platform
                : '';
            $scope.iosPro = typeof app_data != 'undefined' ? app_data.iosPro
                : '';
            $scope.iosDev = typeof app_data != 'undefined' ? app_data.iosDev
                : '';
            $scope.aps = '';
            $scope.android = '';
            $scope.wp = '';
            $scope.tag_list = [];
            $rootScope.select_list = [];// 目标平台

            $scope.select = function (i, platform) {
                var has = $rootScope.select_list.indexOf(i), enble_platform = $scope.platform
                    .indexOf(platform);
                if (has > -1) {
                    $rootScope.select_list.splice(has, 1);
                }
                // iosDev=false:有ios开发环境，但不能选中
                else if ((i > 2 && enble_platform > -1)
                    || (custom_push == 0 || (i == 1 && $scope.iosDev))
                    || (i == 2 && $scope.iosPro)) {
                    $rootScope.select_list.push(i);
                }

                // ios开发环境，ios生产环境同时出现时，只能有一个选中
                if (i == 1 || i == 2) {
                    var another_ios = i == 1 ? 2 : 1, has_another = $rootScope.select_list
                        .indexOf(another_ios);
                    if (has_another > -1)
                        $rootScope.select_list.splice(has_another, 1);
                }
            };
            $rootScope
                .$watchCollection(
                    'select_list',
                    function (select_list) {
                        $scope.aps = '';
                        $scope.android = '';
                        $scope.wp = '';
                        if (select_list.length > 0)
                            max_word = max_words[select_list[0] - 1];
                        else
                        // max_word=72;
                            max_word = 1333;

                        for (var i = 0, len = select_list.length; i < len; i++) {
                            switch (select_list[i]) {
                                case 1:
                                    $scope.aps = 'ios';
                                    break;
                                case 2:
                                    $scope.aps = 'ios-product';
                                    break;
                                case 3:
                                    $scope.android = 'on';
                                    break;
                                case 4:
                                    $scope.wp = 'on';
                                    break;
                            }
                            // 有多个平台时，输入字数限制取平台中最多的字数限制
                            var platform_word = max_words[select_list[i] - 1];
                            if (platform_word < max_word)
                                max_word = platform_word;
                        }
                        // 自定义发送是240个字
                        max_word = custom_push == 0 ? 1333
                            : max_word;
                        utils.word_count(max_word,
                            count_service);
                    });
            var platform_arr = $scope.platform.split(',');
            // 页面加载时，就选中平台
            for (var i = 0, len = platform_arr.length; i < len; i++) {
                switch (platform_arr[i]) {
                    case 'w':
                        $scope.select(4, 'w');
                        break;
                    case 'i':
                        if ($scope.iosDev)
                            $scope.select(1, 'i');
                        if (custom_push == 1 && $scope.iosPro)
                            $scope.select(2, 'i');
                        break;
                    default:
                        $scope.select(3, 'a');
                }
            }

            // 页面加载时，如果是新页面，默认都不选中平台，如果是转发，之前是什么平台，现在就选中什么平台
            if (push) {
                if (push.platform.indexOf("ios") >= 0) {
                    if (push.platform.indexOf("ios-product") >= 0) {
                        $scope.select(2, 'i')
                    } else {
                        $scope.select(1, 'i')
                    }
                }
                if (push.platform.indexOf("android") >= 0) {
                    $scope.select(3, 'a')
                }
                if (push.platform.indexOf("winphone") >= 0) {
                    $scope.select(4, 'w')
                }
            }

            // 登录
            // $scope.submit = function(){
            // $http({
            // method: 'POST',
            // url: base+"/accounts/login",
            // data: {
            // 'username': '791127866@qq.com',
            // "password": '53452827',
            // 'isRemember': true,
            // 'captcha':0,
            // 'nextUrl':''
            // }
            // }).then(function successCallback(data) {
            // alert(JSON.stringify(data));
            //
            // }, function errorCallback(data) {
            //
            // });
            // }

            // console.log(push.platform);
            $scope.remove = function (array, index) {
                array.splice(index, 1);
                if ($scope.cur == 6)// 用户分群还要同步删除segment id
                    $scope.seg_ids.splice(index, 1);
            };
            $scope.top = 30;
            $scope.tag_arr = []
            var temp_input = '';
            $scope.tag_show = [];// tag_show:过滤后的tag列表
            $scope.tag_cursor = -1;// 搜索下拉框当前位置,-1表示没有下拉框没有任何选中
            $scope.show_tip_or_del = function (event) {
                var url;
                if ($scope.cur == 2) {// tag输入实时加载数据
                    if (event.keyCode < 37 || event.keyCode > 40) {
                        if (appKey != '') {
                            url = base + '/push/app/' + appKey
                                + '/push/tags';
                        } else {
                            url = base + '/push/group/' + groupKey
                                + '/push/tags';
                        }
                        url = '/TopVisionWeb/app/glass/findByTags.do?tag='
                            + $scope.input;
                        $http.get(url).then(
                            function successCallback(data) {
                                $scope.tag_arr = data.data.data;
                                $scope.tag_show = $scope.tag_arr;
                                $scope.tag_cursor = -1;// 重置选中
                                temp_input = $scope.input;// 暂时保存输入
                                search_menu();// 更新搜索列
                            }, function errorCallback(response) {
                                alert(JSON.stringify(response));
                            });

                        // var data = {
                        // 'username' : '791127866@qq.com',
                        // "password" : '53452827',
                        // 'isRemember' : true,
                        // 'captcha' : '1234',
                        // 'nextUrl' : ''
                        // };
                        // $http.post(
                        // "/TopVisionWeb/app/account/login.do",
                        // data).then(function(data) {
                        // alert(JSON.stringify(data));
                        // });
                    } else {
                        search_menu();
                        if (event.keyCode == 40)// 向下
                            $scope.tag_cursor = $scope.tag_cursor == $scope.tag_show.length - 1 ? 0
                                : $scope.tag_cursor + 1;

                        if (event.keyCode == 38)
                            $scope.tag_cursor = $scope.tag_cursor == 0 ? $scope.tag_show.length - 1
                                : $scope.tag_cursor - 1;

                        $scope.input = $scope.tag_show[$scope.tag_cursor];
                    }
                }
                if ($scope.cur == 6) {// 用户分群
                    $scope.seg_show = [];
                    if (event.keyCode != 37 && event.keyCode != 38
                        && event.keyCode != 39
                        && event.keyCode != 40) {// 不是箭头
                        $scope.seg_cursor = -1;// 重置选中
                        temp_input = $scope.input;
                        search_seg();
                    } else {
                        search_seg();
                        if (event.keyCode == 40)// 向下
                            $scope.seg_cursor = $scope.seg_cursor == $scope.seg_show.length - 1 ? 0
                                : $scope.seg_cursor + 1;

                        if (event.keyCode == 38)
                            $scope.seg_cursor = $scope.seg_cursor == 0 ? $scope.seg_show.length - 1
                                : $scope.seg_cursor - 1;

                        $scope.input = $scope.seg_show[$scope.seg_cursor];
                    }
                }
            };
            $scope.select_tag = function (tag) {// 选中下拉框中的选项
                // alert(tag);
                $scope.input = tag;
                $scope.tag_show = [];// 保存搜索下拉框选项
                if ($scope.tag_list.indexOf($scope.input) == -1) {
                    $scope.tag_list.push($scope.input);
                    $scope.input = '';
                }
            };
            $scope.select_seg = function (seg) {
                for (var i = 0, len = $scope.seg_list.length; i < len; i++) {
                    var seg_item = $scope.seg_list[i];
                    if (seg_item.segmentName == seg) {
                        $scope.seg_show = [];
                        if ($scope.distribute_push.indexOf(seg) == -1) {
                            $scope.distribute_push.push(seg);
                            $scope.seg_ids.push(seg_item.segmentId);// 显示的是segment
                            // name,传的是segment
                            // id
                        }
                        $scope.input = '';
                    }
                }
            };

            function search_menu() {// 生成搜索菜单
                $scope.tag_show = [];
                if ($scope.input != '') {
                    for (var i = 0, len = $scope.tag_arr.length; i < len; i++) {
                        if ($scope.tag_arr[i].indexOf(temp_input) > -1)
                            $scope.tag_show.push($scope.tag_arr[i]);
                    }
                }
            }

            $scope.seg_list = [];
            $scope.seg_cursor = -1;
            $scope.seg_show = [];
            $scope.seg_ids = [];

            function search_seg() {
                if ($scope.input != '') {
                    for (var i = 0, len = $scope.seg_list.length; i < len; i++) {
                        if ($scope.seg_list[i].segmentName
                                .indexOf(temp_input) > -1)
                            $scope.seg_show
                                .push($scope.seg_list[i].segmentName);
                    }
                }
            }

            $scope.add = function (event) {
////						alert(("#alert_content").val());
////						console.log($scope.content);
//						if($scope.content == 'pushFile'){
//							alert("该模式仅支持单个文件推送");
//						}
                $scope.top = $('.wrap-detail').height() + 3;
                if ($scope.input != '' && event.keyCode == 13) {// 回车
                    switch ($scope.cur) {
                        case 2:
                            if ($scope.tag_list.indexOf($scope.input) == -1
                                && $scope.tag_list.length < 20
                                && $scope.input.length <= 40)
                                $scope.tag_list.push($scope.input);
                            break;
                        case 3:
                            if ($scope.alias.indexOf($scope.input) == -1
                                && $scope.alias.length < 1000
                                && $scope.input.length <= 40)
                                $scope.alias.push($scope.input);
                            break;
                        case 5:
                            if ($scope.regis_id.indexOf($scope.input) == -1
                                && $scope.regis_id.length < 1000)
                                $scope.regis_id.push($scope.input);
                            break;
                        case 6:
                            if ($scope.distribute_push
                                    .indexOf($scope.input) == -1
                                && $scope.distribute_push.length < 40) {
                                for (var i = 0, len = $scope.seg_list.length; i < len; i++) {
                                    var seg = $scope.seg_list[i];
                                    if (seg.segmentName == $scope.input) {
                                        $scope.distribute_push
                                            .push($scope.input);
                                        $scope.seg_ids.push(seg.segmentId)
                                    }
                                }
                            }
                            break;
                    }
                    $scope.input = '';
                }
            };
            $scope.del_by_keyboard = function (event) {
                if ($scope.input == '' && event.keyCode == 8) {
                    switch ($scope.cur) {
                        case 2:
                            $scope.tag_list.splice(
                                $scope.tag_list.length - 1, 1);
                            break;
                        case 3:
                            $scope.alias.splice($scope.alias.length - 1, 1);
                            break;
                        case 5:
                            $scope.regis_id.splice(
                                $scope.regis_id.length - 1, 1);
                            break;
                        case 6:
                            var index = $scope.distribute_push.length - 1;
                            $scope.distribute_push.splice(index, 1);
                            $scope.seg_ids.splice(index, 1);
                            break;
                    }
                }
            }
            $scope.paste = function (event) {
                $rootScope
                    .add_by_comma(event.originalEvent.clipboardData
                        .getData('text/plain'));
                $scope.input = '';
                event.preventDefault();
            };
            $rootScope.add_by_comma = function (content) {// 以逗号分开的输入
                if (content != '') {
                    var arr = content.split(',');
                    for (var i = 0, len = arr.length; i < len; i++) {
                        var item = arr[i].trim();
                        switch ($scope.cur) {
                            case 2:
                                if ($scope.tag_list.indexOf(item) == -1
                                    && $scope.tag_list.length < 20)
                                    $scope.tag_list = $scope.tag_list
                                        .concat(item);
                                break;
                            case 3:
                                if ($scope.alias.indexOf(item) == -1
                                    && $scope.alias.length < 1000)
                                    $scope.alias = $scope.alias
                                        .concat(item);
                                break;
                            case 5:
                                if ($scope.regis_id.indexOf(item) == -1
                                    && $scope.regis_id.length < 1000)
                                    $scope.regis_id = $scope.regis_id
                                        .concat(item);
                                break;
                            case 6:
                                if ($scope.distribute_push.indexOf(item) == -1
                                    && $scope.distribute_push.length < 40) {
                                    for (var i = 0, len = $scope.seg_list.length; i < len; i++) {
                                        var seg = $scope.seg_list[i];
                                        if (seg.segmentName == item) {
                                            $scope.distribute_push
                                                .push(item);
                                            $scope.seg_ids
                                                .push(seg.segmentId)
                                        }
                                    }
                                }
                                break;
                        }
                    }
                    $scope.input = '';
                }
            };
            $scope.focus_input = function () {
                document.querySelector(
                    '.wrap-detail li:last-child input').focus();
            };
            $scope.tag_temp = '';
            $scope.alias_temp = '';
            $scope.regis_id_temp = '';
            $scope.distribute_push_temp = '';
            $scope.currentSegmentId = '';

            function dispatch_input(i, input) {
                switch (i) {
                    case 2:
                        $scope.tag_temp = input;
                        break;
                    case 3:
                        $scope.alias_temp = input;
                        break;
                    case 5:
                        $scope.regis_id_temp = input;
                        break;
                    case 6:
                        $scope.distribute_push_temp = input;
                        break;
                }
            }

            function receive_input(i) {// 将暂存内容写回输入框
                switch (i) {
                    case 2:
                        $scope.input = $scope.tag_temp;
                        break;
                    case 3:
                        $scope.input = $scope.alias_temp;
                        break;
                    case 5:
                        $scope.input = $scope.regis_id_temp;
                        break;
                    case 6:
                        $scope.input = $scope.distribute_push_temp;
                        break;
                }
            }

            $scope
                .$watch(
                    'cur',
                    function (cur, last) {
                        dispatch_input(last, $scope.input);// 写入上一个输入框中的内容
                        receive_input(cur);// 输入框内容先暂存在$scope.input,有暂存用户输入这个需求
                        if (cur == 6) {// 用户分群数据量小，所以切换时就拉数据，输入时不实时
                            $rootScope.segmentBorderDefault();

                            var url;
                            if (appKey != '') {
                                url = base + '/push/app/'
                                    + appKey
                                    + '/segment/list_data';
                            } else {
                                url = base
                                    + '/push/group/'
                                    + groupKey
                                    + '/push/segment/list_data';
                            }
                            $http({
                                method: 'GET',
                                url: url
                            })
                                .then(
                                    function successCallback(data) {
                                        $scope.seg_list = data.data.data;
                                        if (typeof push != 'undefined'
                                            && push.receiverValue != '') {// 如果是转发，将对应segment
                                            // name显示出来
                                            var seg_ids = push.receiverValue
                                                .split(',');
                                            $scope.seg_ids = seg_ids;
                                            var seg_temp = [];
                                            $scope.distribute_push = [];
                                            for (var i = 0, len = $scope.seg_list.length; i < len; i++) {
                                                for (var j = 0, len1 = seg_ids.length; j < len1; j++) {
                                                    if (seg_ids[j] == $scope.seg_list[i].segmentId) {
                                                        $scope.distribute_push
                                                            .push($scope.seg_list[i].segmentName)
                                                        seg_temp
                                                            .push(seg_ids[j]);

                                                        $scope.currentSegmentId = $scope.seg_list[i].segmentId;
                                                        $timeout(
                                                            function () {
                                                                $(
                                                                    "#segmentValue")
                                                                    .val(
                                                                        $scope.currentSegmentId)
                                                                    .trigger(
                                                                        "change");
                                                            },
                                                            10);
                                                    }
                                                }
                                            }
                                            $scope.seg_ids = seg_temp;
                                        }
                                    },
                                    function errorCallback(response) {

                                    });
                        }

                    });
            $scope
                .$on(
                    'gather_params',
                    function () {
                        var recipient_type = $scope.cur == 4 ? 'broadcast'
                            : $scope.cur == 2 ? 'tags'
                                : $scope.cur == 3 ? 'alias'
                                    : $scope.cur == 5 ? 'registrationid'
                                        : 'segmentid';
                        var params = {
                            recipientType: recipient_type,
                            deviceTags: $scope.tag_list.join(
                                ',')
                                .replace(/[\r\n]*/g, ''),
                            deviceAlias: $scope.alias
                                .join(',').replace(
                                    /[\r\n]*/g, ''),
                            deviceRegistrationid: $scope.regis_id
                                .join(',').replace(
                                    /[\r\n]*/g, ''),
                            deviceSegmentid: $scope.currentSegmentId,// $scope.seg_ids.join(','),
                            android: $scope.android,
                            aps: $scope.aps
                        };
                        if (custom_push == 1)
                            params['wp'] = $scope.wp;

                        $scope.$emit('update_form', params);
                    });

            // 用户分群边框默认
            $rootScope.segmentBorderDefault = function () {
                $(
                    ".select2-container--default .select2-selection--single")
                    .css("border", "1px solid #c4c5c5");
                $(
                    ".select2-container--default .select2-selection--single")
                    .removeClass("empty-input-red-border");
            }
            // 用户分群边框变红
            $rootScope.segmentBorderRed = function () {
                $(
                    ".select2-container--default .select2-selection--single")
                    .css("border", "1px solid #f1394a");
                $(
                    ".select2-container--default .select2-selection--single")
                    .addClass("empty-input-red-border");
            }

            $rootScope.isOpen = false;

            /** 目标人群，unfocus的时候判断是否填写* */
            $scope.checkEmptyTag = function () {
                var index = $('.wrap-detail').attr('index');
                if (index == 6) { // 用户分群
                    $scope.currentSegmentId = $('#segmentValue').val();
                    $scope.currentSegmentId ? $rootScope
                        .segmentBorderDefault() : $rootScope
                        .segmentBorderRed();
                } else {
                    if ($scope.cur != 4
                        && $(
                            ".wrap-detail li[ng-show='cur=="
                            + index + "']").size() == 0
                        && $scope.input == "") {
                        $scope.emptyInput = {
                            tag: true
                        }
                    } else {
                        $scope.emptyInput = {
                            tag: false
                        }
                    }
                }
            }

        });
app
    .controller(
        'push_time',
        function ($scope) {
            tab($scope);
            $scope.solid_push = false;
            $scope.deliveryType = 1;
            $scope.deliveryValue = '';
            $scope.deliveryDate = new Date().Format("yyyy-MM-dd");
            $scope.deliveryTime = new Date().Format("hh:mm:ss");
            $scope.minDate = new Date();
            $scope.tempStartDate = new Date();
            $scope.durationTime = '';
            $scope.focus = function (event) {
                $('.date-picker').toggle();
                event.stopPropagation();// 阻止冒泡，因为document上监听了
            };
            $scope.select = function () {
                $scope.deliveryDate = $scope.tempStartDate
                    .Format("yyyy-MM-dd");
                $('.date_picker').hide();
            };
            $scope.stop_propa = function (event) {// 点击日期选择的月份跳转
                var target = event.target, find_span = $(target).find(
                    'span'), span = target.tagName == 'SPAN' ? $(target)
                    : find_span.size() > 0 ? find_span : null;
                if (span == null || span.is('.text-muted'))
                    event.stopPropagation();
            };
            $scope.$on('gather_params', function () {
                $scope.$emit('update_form', {
                    deliveryType: $scope.cur == 1 ? 'now'
                        : 'scheduled',
                    deliveryDate: $scope.deliveryDate,
                    deliveryTime: $scope.deliveryTime,
                    durationTime: $scope.durationTime
                });
            });
            $scope.$watch('cur',
                function (cur) {
                    if (cur == 2) {
                        $scope.tempStartDate = new Date();
                        $scope.deliveryDate = $scope.tempStartDate
                            .Format("yyyy-MM-dd");
                        $scope.deliveryTime = new Date()
                            .Format("hh:mm:ss");
                        $('.date-picker').show();
                    }

                    $scope.$emit('update_post_text', $scope.cur);
                });

            $scope.emptyInput = {};
            $scope.checkEmptyPushTime = function () {
                var date = $(".schedule-date input").val(), time = $(
                    ".schedule-time input[ng-model='deliveryTime']")
                        .val(), date_reg = /^(\w+){4}-(\w+){2}-(\w+){2}/, time_reg = /^(\w+){2}:(\w+){2}:(\w+){2}/,
                    parse_time = Date
                        .parse((date + ' ' + time).replace(/-/g, "/"));
                if ($('.push-time-tab').attr('index') == 2) {
                    if (date_reg.test(date) && time_reg.test(time)
                        && $.isNumeric(parse_time)
                        && parse_time > new Date().getTime()) {
                        // 定时，且时间ok;
                        $scope.emptyInput.pushTime = false;
                    } else {
                        // 不是定时，或者时间不符合;
                        $scope.emptyInput.pushTime = true;
                    }
                }
            };

            $scope.checkEmptySolidPush = function () {
                var val = $("input[ng-model='durationTime']").val();
                // var numReg = /^[0-9]*$/;
                // //只能输入整数，小数点返回false。现在改成后台四舍五入处理，去掉了&&
                // numReg.test(val)的条件
                if ($scope.solid_push) {
                    if (val >= 0 && val <= 1440 && $.isNumeric(val)) {
                        console.log("ok");
                        $scope.emptyInput.solidPush = false;
                    } else {
                        console.log("noky");
                        $scope.emptyInput.solidPush = true;
                    }
                }
            };

        });
app
    .controller(
        'option-settings',
        function ($scope, count_service, $rootScope) {
            $scope.open = 0;
            $scope.alert_title = typeof push == 'undefined' ? ''
                : 'title' in push ? push['title'] : '';
            $scope.android_notification_bar_id = typeof push == 'undefined' ? ''
                : ('builderId' in push && push['builderId'] != 0) ? push['builderId']
                    : '';
            $scope.show_detail = function () {
                $scope.open = !$scope.open;
            };
            $scope.key_list = [''];// 附加字段的key列表
            $scope.val_list = [''];
            $scope.timeToLive = {
                value: 86400,
                content: '默认(1天)'
            };
            $scope.custom_ttl = '';// 自定义离线消息保留时间
            $scope.silent_push = false;
            var extras = (typeof push != 'undefined' && 'extras' in push) ? JSON
                    .parse(push['extras'])
                : null, ios = (extras != null && 'ios' in extras) ? extras.ios
                : null, keys = extras != null ? Object.keys(extras)
                : null;
            if (extras != null) {
                if (keys != null && keys.length > 0) {
                    $scope.key_list = [];
                    $scope.val_list = [];
                }
                for (var key in extras) {
                    if (key != 'ios' && key != '_open_page') {
                        $scope.key_list.push(key);
                        $scope.val_list.push(extras[key]);
                    }
                }

                if ($scope.key_list.length === 0) {
                    $scope.key_list = [''];
                    $scope.val_list = [''];
                }
            }
            $scope.content_available = (ios != null && 'content-available' in ios) ? !!ios['content-available']
                : false;
            $scope.sound = (ios != null && 'sound' in ios) ? ios['sound']
                : 'default';
            $scope.badge = (ios != null && 'badge' in ios) ? ios['badge']
                : '1';
            $scope.category = (ios != null && 'category' in ios) ? ios['category']
                : '';
            $scope.iosTitle = push ? push.iosTitle : "";
            $scope.iosSubtitle = push ? push.iosSubtitle : ""; // iosTitle和iosSubtitle不在extras里面，在最初数据处理时候已经赋值给同名$scope.iosTitle了
            $scope.mutable_content = (ios != null && 'mutable-content' in ios) ? !!ios['mutable-content']
                : false;
            $scope.open_page = (extras != null && '_open_page' in extras) ? extras['_open_page']
                : '';
            $scope.option_list = [{
                value: 86400,
                content: '默认(1天)'
            }, {
                value: 0,
                content: '0 - 不保留'
            }, {
                value: 60,
                content: '1分钟'
            }, {
                value: 600,
                content: '10分钟'
            }, {
                value: 3600,
                content: '1小时'
            }, {
                value: 10800,
                content: '3小时'
            }, {
                value: 43200,
                content: '12小时'
            }, {
                value: 259200,
                content: '3天'
            }, {
                value: 864000,
                content: '10天'
            }, {
                value: -1,
                content: '自定义'
            }];
            $scope.add = function () {
                $scope.key_list.push('');
                $scope.val_list.push('');
            };
            $scope.del = function (i) {
                $scope.key_list.splice(i, 1);
                $scope.val_list.splice(i, 1);
            };
            $scope.$watch('silent_push', function (val) {// silent_push勾选，自动勾选content_available
                if (val) {
                    $("textarea[ng-model='content']").attr('disabled',
                        'disabled');// 同时禁掉推送编辑框
                    $scope.content_available = true;
                } else
                    $("textarea[ng-model='content']").removeAttr(
                        'disabled');
            });
            $scope.$watchCollection('key_list', function (key_list) {
                count_service.key_list = key_list;
                utils.word_count(max_word, count_service);
            });
            $scope.$watchCollection('val_list', function (val_list) {
                count_service.val_list = val_list;
                utils.word_count(max_word, count_service);
            });
            $scope
                .$on(
                    'gather_params',
                    function () {
                        var custom_keys = [], check_android = $rootScope.select_list
                            .indexOf(3) > -1, check_ios = $rootScope.select_list
                                .indexOf(1) > -1
                            || $rootScope.select_list
                                .indexOf(2) > -1, check_wp = $rootScope.select_list
                            .indexOf(4) > -1;
                        for (var i = 0, len = $scope.key_list.length; i < len; i++)
                            custom_keys
                                .push($scope.val_list[i]);

                        var ttl = $scope.timeToLive.value;
                        var params = {
                            timeToLive: ttl == -1 ? $scope.custom_ttl
                                : ttl,
                            customKeys: JSON
                                .stringify(custom_keys),
                        };
                        // 只传递相应平台所需的参数
                        if (check_android) {
                            params['alertTitle'] = $scope.alert_title;
                            params['androidNotificationBarId'] = $scope.android_notification_bar_id;
                        }
                        if (check_ios && custom_push == 1) {
                            params['contentAvailable'] = $scope.content_available;
                            params['silentPush'] = $scope.silent_push;
                            params['sound'] = $scope.sound;
                            params['badge'] = $scope.badge;
                            params['category'] = $scope.category;
                            params['iosTitle'] = $scope.iosTitle;
                            params['iosSubtitle'] = $scope.iosSubtitle;
                            params['mutableContent'] = $scope.mutable_content;
                        }
                        if (check_wp)
                            params['openPage'] = $scope.open_page;

                        $scope.$emit('update_form', params);
                    });

            if (typeof push != 'undefined') {
                utils.insert_val(push);
            }// 将转发过来的数据写入

            $scope.emptyInput = {};
            $scope.checkEmptyOfflinePush = function (item) {
                var val = $("input[ng-model='custom_ttl']").val();
                // var numReg = /^[0-9]*$/;
                // //只能输入整数，小数点返回false。现在改成后台四舍五入处理，去掉了 &&
                // numReg.test(val) 的判断条件
                if (item && item.value == -1) {
                    // 针对select的ng-change事件，如果切换到自定义，不立马校验是否为空。如果不判断，change的时候会立马变红。
                } else if ($scope.open
                    && $('.option-settings-main .select-option')
                        .find('option:selected').attr('label') == '自定义') {
                    // 对应click-anywhere-but-here事件，当页面选中为自定义的时候，unFocus时对input进行校验
                    if (val >= 0 && val <= 864000 && val != ''
                        && $.isNumeric(val)) {
                        $scope.emptyInput.offlinePush = false;
                    } else {
                        $scope.emptyInput.offlinePush = true;
                    }
                } else {
                    // 当从自定义的option，转到其它option时，将select的红色外框去掉。
                    $scope.emptyInput.offlinePush = false;
                }
            };
        });
app
    .controller(
        "info_modal",
        function ($scope, $http, $uibModalInstance, $uibModal,
                  hintTitle, hintText, confirmText, cancelText, params,
                  scope) {
            $scope.hintTitle = hintTitle;
            $scope.hintText = hintText;
            $scope.confirmText = confirmText;
            $scope.cancelText = cancelText;
            $scope.show_confirm = true;// 用来区分是否展示推送历史这些权限的判断，默认没有权限，即展示
            $scope.cancel = function () {
                $uibModalInstance.dismiss();
            };
            $scope.confirm = function () {
                $uibModalInstance.close();
            };
            $uibModalInstance.result
                .then(
                    function () {
                        // var url = '../message/send';
                        // alert(url);
                        //alert("1111");
                        scope.errorCode = 0;
                        scope.show_loading = 1;
                        scope.$broadcast('gather_params',
                            params);// 收集所有参数
                        return $http({
                            method: 'POST',
                            url: '../message/send',
                            headers: {
                                'Content-type': 'application/json'
                            },
                            data: params
                        });

                    })
                .then(
                    function (result) {
                        // alert(JSON.stringify(data));
                        console.log(result.data.code);
                        if (result.data.code == 0) {
                            $uibModal
                                .open({
                                    templateUrl: 'info_modal_tpl',
                                    controller: 'post_success_modal',
                                    resolve: {
                                        hintTitle: function () {
                                            return "提示";
                                        },
                                        hintText: function () {
                                            return params.deliveryType == 'now' ? "推送成功"
                                                : '定时推送添加成功';
                                        },
                                        confirmText: function () {
                                            return '刷新';
                                        },
                                        // cancelText :
                                        // function() {
                                        // return '留下来继续发送!
                                        // ';
                                        // },
                                        cancelText: function () {
                                            return '确定';
                                        },
                                        params: function () {
                                            return params;
                                        }
                                    }
                                });
                        } else {
                            $('html,body').animate({
                                scrollTop: 0
                            }, 'fast');
                            var errorCode = result.data.code, keys = Object
                                .keys(error_suggest);

                            console.log("errorCode" + result.data.code, "keys=" + keys);
                            var filter_func = function (ele) {
                                return ele == errorCode;
                            };
                            var in_array = keys
                                .filter(filter_func);
                            scope.errorCode = in_array.length > 0 ? errorCode
                                : '1';// 显示默认错误
                        }

                        scope.show_loading = 0;
                    })
            // .catch(function(error){
            // if( error ){
            // scope.errorCode='2';//显示默认错误
            // $('html,body').animate({ scrollTop: 0 }, 'fast');
            // }
            // scope.show_loading=0;
            // });

        });

app
    .controller(
        "post_success_modal",
        function ($scope, $window, $uibModalInstance, hintTitle,
                  hintText, confirmText, cancelText, params) {
            $scope.hintTitle = hintTitle;
            $scope.hintText = hintText;
            $scope.confirmText = confirmText;
            $scope.cancelText = cancelText;
            $scope.show_confirm = (push_permis['parentId'] == '0' || push_permis['history'] != '') ? true
                : false;
            $scope.cancel = function () {
                $uibModalInstance.dismiss();
            };
            $scope.confirm = function () {
                $uibModalInstance.close();
            };
            $uibModalInstance.result
                .then(function () {
                    window.onbeforeunload = null;
                    var path = $window.location.pathname, reg = /\/push\/(group|app)\/(\w+)\/\w+\/\w+/,
                        replace = '/push/$1/$2/push/history';

                    if (params.deliveryType == 'scheduled')
                        replace += '/scheduled';

                    if (custom_push == 0)
                        replace += '?type=0'

                    location.href = path.replace(reg, replace);
                });
        });

app
    .controller(
        'form',
        function ($rootScope, $scope, $http, $window, $uibModal,
                  count_service) {
            $(document)
                .ready(
                    function () {// 自定义blur事件
                        $(document)
                            .bind(
                                'click',
                                function (event) {
                                    var target = $(event.target);
                                    if (!target
                                            .hasClass('search-item')
                                        && !target
                                            .hasClass('add-input')) {// 如果点击的不是搜索下拉框的选项
                                        $rootScope
                                            .add_by_comma($(
                                                '.add-input')
                                                .val());
                                    }
                                });

                        // segment下拉框初始化
                        $('#segmentValue')
                            .select2({
                                placeholder: "请选择一个用户分群",
                                width: "100%"
                            })
                            .on(
                                "change",
                                function (e) {
                                    $rootScope
                                        .segmentBorderDefault();
                                    $("#segmentValue")
                                        .scope().currentSegmentId = $(
                                        '#segmentValue')
                                        .val();
                                })
                            .on(
                                "select2:open",
                                function (e) {
                                    $rootScope.isOpen = true;
                                })
                            .on(
                                "select2:close",
                                function (e) {
                                    $rootScope.isOpen = false;
                                });
                    });
            var params = {
                type: custom_push,
                deliveryTimezone: 'Asia/Hong_Kong'
            };
            $scope.$on('update_form', function (event, data) {// 更新参数列表
                for (key in data)
                    params[key] = data[key]
            });
            $scope.post_text = '立即发送';
            $scope.$on('update_post_text', function (event, data) {
                $scope.post_text = data == 1 ? '立即发送' : '预定推送';
            });
            $scope.error_suggest = error_suggest;
            $scope.errorCode = 0;
            $scope.valid = 0;

            function check_field(func) {
                if (!func())// not valid
                    return false;
                else
                    return true;
            }

            var rules = [// 列出不符合要求的情况
                function () {//最上面输入框
                    return check_field(function () {
                        return
                        utils.word_count(max_word, count_service) > max_word;
                    });
                },
                function () {
                    return check_field(function () {// 目标平台
                        return $(
                            ".target-plattform li[class='selected']")
                            .size() == 0;
                    });
                },
                function () {
                    return check_field(function () {// 目标对象
                        var index = $('.wrap-detail').attr('index');
                        if (index == 6) {
                            return $("#segmentValue").scope().currentSegmentId ? false
                                : true;
                        }
                        // 广播发送按钮不变灰
                        return index != 4
                            && $(
                                ".wrap-detail li[ng-show='cur=="
                                + index + "']")
                                .size() == 0;
                    });
                },
                function () {
                    return check_field(function () {// 定速推送
                        var val = $(
                            "input[ng-model='durationTime']")
                            .val();
                        // var numReg = /^[0-9]*$/;
                        // //只能输入整数，小数点返回false。现在改成后台四舍五入，去掉了||
                        // !numReg.test(val) 判断。
                        return $("input[ng-model='solid_push']")
                                .is(':checked')
                            && (val < 0 || val > 1440 || !$
                                .isNumeric(val));
                    });
                },
                function () {
                    return check_field(function () {// 附加字段
                        function del_empty(value) {
                            return value != ''
                        }

                        var flag = false, list = $('#extra-input li'), key_list = [];
                        $('#extra-input input').removeAttr('style');
                        for (var i = 0, len = list.size(); i < len; i++) {
                            var item = $(list[i]), key_input = item
                                .find("input[ng-model='key_list[$index]']"), key = key_input
                                .val(), val = item
                                .find(
                                    "input[ng-model='val_list[$index]']")
                                .val(), repeat = key_list
                                .indexOf(key) > -1;
                            if (repeat) {// 输入的key与之前的有重复
                                key_input.css('color', 'red');
                            }

                            if ((key != '' && val == '')
                                || (key == '' && val != '')
                                || repeat) {
                                flag = true;
                                // break;
                            }
                            key_list.push(key);
                        }

                        var filter = key_list.filter(del_empty);
                        if (key_list.length - filter.length >= 2)// 有2行及以上的空白key,value
                            flag = true;

                    });
                },
                function () {
                    return check_field(function () {// 自定义消息保留时长
                        var val = $("input[ng-model='custom_ttl']")
                            .val();
                        // var numReg = /^[0-9]*$/;
                        // //只能输入整数，小数点返回false。现在改成后台四舍五入，去掉 ||
                        // !numReg.test(val)的判断。
                        return $(
                            '.option-settings-main .select-option')
                                .find('option:selected').attr(
                                'label') == '自定义'
                            && (val < 0 || val > 864000
                                || val == '' || !$
                                    .isNumeric(val));
                    });
                },
                function () {
                    return check_field(function () {// 定时推送
                        var date = $(".schedule-date input").val(), time = $(
                            ".schedule-time input[ng-model='deliveryTime']")
                                .val(), date_reg = /^(\w+){4}-(\w+){2}-(\w+){2}/, time_reg = /^(\w+){2}:(\w+){2}:(\w+){2}/,
                            parse_time = Date
                                .parse((date + ' ' + time).replace(
                                    /-/g, "/"));
                        return $('.push-time-tab').attr('index') == 2
                            && (!date_reg.test(date)
                                || !time_reg.test(time)
                                || !$.isNumeric(parse_time) || parse_time <= new Date()
                                    .getTime())
                    });
                }

            ];
            if (parseInt(custom_push) == 1) {// 自定义消息不需要校验这两个
                rules = rules
                    .concat([
                        function () {
                            return check_field(function () {// ios
                                // badge
                                var input = $("input[ng-model='badge']"), val = input
                                    .val();
                                var r = val != ''
                                    && !$.isNumeric(val);
                                if (r)
                                    input.css('color', 'red');
                                else
                                    input.removeAttr('style');

                                return r;
                            });
                        },
                        function () {
                            return check_field(function () {// 通知样式编号
                                var input = $("input[ng-model='android_notification_bar_id']"), val = input
                                    .val();
                                var r = val != ''
                                    && (val <= 0
                                        || val > 1000 || !$
                                            .isNumeric(val));
                                if (r)
                                    input.css('color', 'red');
                                else
                                    input.removeAttr('style');

                                return r;
                            });
                        }]);
            }

            // 定时去查看valid状态,当valid = 1,发送按钮可以点击
            setInterval(function () {
                $scope.$apply(function () {
                    $scope.valid = 1;
                });
                for (var i = 0, len = rules.length; i < len; i++) {
                    var rule = rules[i]();
                    if (rule) {// 有一个不符合要求，则退出
                        $scope.$apply(function () {
                            $scope.valid = 0;
                        });
                        break;
                    }
                }
            }, 500);
            $scope.show_loading = 0;
            $scope.overLong = {
                is: false
            };
            $scope.post = function () {
                if ($scope.valid == 1
                    && utils.word_count(max_word, count_service) > max_word
                    && custom_push == 1) {
                    /** 字数超限的error提示* */
                    $scope.overLong.is = true;
                    $scope.overLong.error = "消息体太大";
                    $scope.overLong.suggest = '<li>输入内容长度超过限制，Android和WinPhone平台长度限制为4000字节， iOS平台长度限制为2000字节，因采用UTF-8编码，一个汉字为3字节，当选择多个平台时，以最短为上限。</li><li>建议您根据长度限制规则修改下推送内容和附加字段。</li>';
                    $('html,body').animate({
                        scrollTop: 0
                    }, 'fast');
                } else if ($scope.valid == 1
                    && utils.word_count(max_word, count_service) > max_word
                    && custom_push == 0) {
                    /** 字数超限的error提示* */
                    $scope.overLong.is = true;
                    $scope.overLong.error = "消息体太大";
                    $scope.overLong.suggest = '<li>输入内容长度超过限制，Android和iOS平台长度限制为4000字节， 因采用UTF-8编码，一个汉字为3字节，当选择多个平台时，以最短为上限。</li><li>建议您根据长度限制规则修改下推送内容和附加字段。</li>';
                    $('html,body').animate({
                        scrollTop: 0
                    }, 'fast');
                } else if ($scope.valid == 1) {
                    $scope.overLong.is = false;
                    $uibModal.open({
                        templateUrl: 'info_modal_tpl',
                        controller: 'info_modal',
                        resolve: {
                            hintTitle: function () {
                                return "提示";
                            },
                            hintText: function () {
                                return "确认要发送出去吗？";
                            },
                            confirmText: function () {
                                return '发送吧!';
                            },
                            cancelText: function () {
                                return '先等等再说! ';
                            },
                            params: function () {
                                return params;
                            },
                            scope: function () {
                                return $scope;
                            }
                        }
                    });
                }
            };

            window.onbeforeunload = function () {
                if ((count_service.cal_key() + count_service.cal_val() + count_service.content).length != 0) { // 不输入内容直接跳转，输入内容则不跳转
                    return '您编辑的消息还没有发送,如果离开当前页面，消息内容将会丢失。';
                }
            };

        });

var qtip_config = {
    position: {
        my: 'left center',
        at: 'center right'
    },
    style: {
        classes: 'qtip-shadow qtip-rounded my-qtip-style',
        width: '330'
    },
    hide: {
        delay: 1000,
        fixed: true,
        event: 'mouseleave'
    }
};
qtip_config['content'] = {
    text: '<div class="qtip-help-wrapper">'
    + '<span class="top-title">离线消息保留时长</span>'
    + '<span class="line"></span>'
    + '<p class="detail">一条给某个用户的推送，如果该用户当前不在线，则会保存为离线消息，待该用户下次上线时继续推送给他。</p>'
    + '<p class="detail">可以通过该值为指定离线消息的时长。即在该时长范围内用户上线会继续收到推送，否则过期。</p>'
    + '<p class="detail">默认时长为 1 天。最长为 10 天。可以设置为 0，则表示不保留离线消息，即只有当前在线的用户才可以收到，所有不在线的都不会收到。</p>'
    + '</div>'
};
$(".set-reserve i").qtip(qtip_config);

qtip_config['content'] = {
    text: '<div class="qtip-help-wrapper">'
    + '<span class="top-title">通知标题 （Android）</span>'
    + '<span class="line"></span>'
    + '<p class="detail">如果不设置，则默认的通知标题为应用的名称。</p>' + '</div>'
};
$(".notify-title i").qtip(qtip_config);

qtip_config['content'] = {
    text: '<div class="qtip-help-wrapper">'
    + '<span class="top-title">通知栏样式编号 （Android）</span>'
    + '<span class="line"></span>'
    + '<p class="detail">对于 Android通知，JPush提供自定义通知栏样式。在客户端可设置多套样式指定不同的编号，服务器端推送时指定编号就可以展现时使用之前设置的样式。</p>'
    + '<p class="detail">这个值默认值为 0，即使用默认的样式。通知栏样式的定义，请到 http://docs.jiguang.cn/jpush/client/Android/android_api/#api_6 参考相关的文档。</p>'
    + '</div>'
};
$(".notify-num i").qtip(qtip_config);

qtip_config['content'] = {
    text: '<div class="qtip-help-wrapper">'
    + '<span class="top-title">iOS 通知声音 (sound)</span>'
    + '<span class="line"></span>'
    + '<p class="detail">APNs通知，通过这个字段指定声音。默认为default，即系统默认声音。 如果设置为空值，则为静音。</p>'
    + '<p class="detail">如果设置为特殊的名称，则需要你的App里配置了该声音才可以正常。</p>'
    + '</div>'
};
$(".sound i").qtip(qtip_config);

qtip_config['content'] = {
    text: '<div class="qtip-help-wrapper">'
    + '<span class="top-title">通知栏样式编号（Android）</span>'
    + '<span class="line"></span>'
    + '<p class="detail">对于 Android通知，JPush提供自定义通知栏样式。在客户端可设置多套样式指定不同的编号，服务器端推送时指定编号就可以展现时使用之前设置的样式。</p>'
    + '<p class="detail">这个值默认值为 0，即使用默认的样式。通知栏样式的定义，请到 http://docs.jiguang.cn/jpush/client/Android/android_api/#api_6 参考相关的文档。</p>'
    + '</div>'
};
$(".notify-num i").qtip(qtip_config);

qtip_config['content'] = {
    text: '<div class="qtip-help-wrapper">'
    + '<span class="top-title">iOS 通知声音 (sound)</span>'
    + '<span class="line"></span>'
    + '<p class="detail">APNs通知，通过这个字段指定声音。默认为default，即系统默认声音。 如果设置为空值，则为静音。</p>'
    + '<p class="detail">如果设置为特殊的名称，则需要你的App里配置了该声音才可以正常。</p>'
    + '</div>'
};
$(".sound i").qtip(qtip_config);

qtip_config['content'] = {
    text: '<div class="qtip-help-wrapper">'
    + '<span class="top-title">iOS 角标</span>'
    + '<span class="line"></span>'
    + '<p class="detail">可直接指定 APNs 推送通知的 badge，直接展示在桌面应用图标的右上角，含义是应用未读的消息数。也支持如 +12，-3 等运算操作，JPush 会针对每一个用户当前的 badge 做单独的运算，例：接受者 A，B 的角标分别为 1 和 2，那么推送 +2 后 A的角标变为 3，B 的角标变为 4。默认值为 1。</p>'
    + '</div>'
};
$(".badge1 i").qtip(qtip_config);

qtip_config['content'] = {
    text: '<div class="qtip-help-wrapper">'
    + '<span class="top-title">iOS 分类</span>'
    + '<span class="line"></span>'
    + '<p class="detail">只有IOS8及以上系统才支持此参数推送</p>' + '</div>'
};
$(".category i").qtip(qtip_config);

qtip_config['content'] = {
    text: '<div class="qtip-help-wrapper">'
    + '<span class="top-title">附加字段</span>'
    + '<span class="line"></span>'
    + '<p class="detail">用于客户端自定义事件处理。</p>' + '</div>'
};
$(".extra-field i").qtip(qtip_config);

qtip_config['content'] = {
    text: '<div class="qtip-help-wrapper">'
    + '<span class="top-title">silent_push</span>'
    + '<span class="line"></span>'
    + '<p class="detail">如果只携带content-available: 1,不携带任何badge，sound 和消息内容等参数，则可以不打扰用户的情况下进行内容更新等操作即为“Silent Remote Notifications”。</p>'
    + '</div>'
};
// qtip_config['position']={
// my:'top left',
// at:'bottom right'
// };
$(".extra-apple-option li:nth-child(1)").qtip(qtip_config);

qtip_config['content'] = {
    text: '<div class="qtip-help-wrapper">'
    + '<span class="top-title">iOS 通知标题 (title)</span>'
    + '<span class="line"></span>'
    + '<p class="detail">如果不设置，则默认的通知标题为应用的名称。</p>' + '</div>'
};
$(".ios-title i").qtip(qtip_config);